package sudoku;

import javax.swing.*;
import java.awt.event.*;


/**
 *
 * @author Rene
 */
public class gui {
    public static JFrame frame = new JFrame();
    public static JLabel freieFelder = new JLabel();
    static JLabel result = new JLabel();
    static JButton back = new JButton();
    static JButton solveall = new JButton();
    static JButton solve1 = new JButton();
    static JButton possibilities = new JButton();    
    
    static boolean poss = false;
   
    public static void main(){
        for (int i=0; i<9; i++){
            for (int j=0; j<9; j++){
                int x=0,y=0;
                if (i>2) x=5;
                if (i>5) x=10;
                if (j>2) y=5;
                if (j>5) y=10;
                Main.feld[i][j].setBounds(i*100+x+20, j*50+y+20, 100, 50);
                frame.add(Main.feld[i][j]);
                Main.feld[i][j].setVisible(true);
                Main.feld[i][j].action();
            }
        }
        
        solve1.setBounds(950, 240, 80, 30);
        solve1.setVisible(true);
        solve1.setText("1-Feld-Hilfe");
        frame.add(solve1);
        solve1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                back.setEnabled(true);
                Main.save();
                Main.solve1();
                Main.repaintall();
                if (Main.free_fields==0) {
                    solve1.setEnabled(false);
                    solveall.setEnabled(false);
                }
            }
        });
        
        solveall.setBounds(950, 280, 80, 30);
        solveall.setVisible(true);
        solveall.setText("Lösen");
        frame.add(solveall);
        solveall.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Main.save();
                for (int i=Main.free_fields; i!=0; i--){
                    Main.solve1();
                }
                if (Main.free_fields==0) result.setText("gelöst");
                else result.setText("Fehler");
                solveall.setEnabled(false);
                solve1.setEnabled(false);
                back.setEnabled(true);
            }
        });
        
        back.setBounds(950, 380, 80, 30);
        back.setVisible(true);
        back.setText("Zurück");
        frame.add(back);
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Main.load();
                result.setText("");
                back.setEnabled(false);
                solveall.setEnabled(true);
                solve1.setEnabled(true);
            }
        });
        
        possibilities.setBounds(950, 340, 80, 30);
        possibilities.setVisible(true);
        possibilities.setText("Listen");
        frame.add(possibilities);
        possibilities.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                poss = poss? false : true;
                Main.repaintall();
            }
        });
        
        result.setText("");
        result.setBounds(950, 180, 100, 30);
        frame.add(result);
        result.setVisible(true);
        
        freieFelder.setText("Free Fields: " + Main.free_fields);
        freieFelder.setBounds(950, 150, 100, 30);
        frame.add(freieFelder);
        freieFelder.setVisible(true);      
        
        JButton blind = new JButton();
        blind.setVisible(false);
        frame.add(blind);
        frame.setSize(1080, 550);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    }
}